package com.liu.sx.controller;

import com.liu.sx.common.entity.PageResult;
import com.liu.sx.common.entity.Result;
import com.liu.sx.common.status.CodeEnum;
import com.liu.sx.common.util.ChannelHolder;
import com.liu.sx.entity.Task;
import com.liu.sx.netty.Client;
import com.liu.sx.service.TaskService;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {


    @Autowired
    private TaskService taskService;


    @PostMapping("/server")
    public Result setServer(@RequestBody  Task task){
       task.setUserid("11");
        String message=taskService.doIpAndPort(task);
        return new Result(true, CodeEnum.OK.getCode(),message);
    }


    @GetMapping
    public Result getAll(int page,int rows ,String query){
        Page<Task> pages = taskService.findPageTask(page,rows,query);

      return  new Result(true,CodeEnum.OK.getCode(),"查询任务成功",new PageResult<Task>(pages.getTotalElements(),pages.getContent()));

    }


}
